package com.project.common.util;

import java.util.List;

/**
 * 作者:李明
 * 时间:2012-10-11
 * 模块 通用模块
 * 说明:分页工具类
 */

public class QueryUtils {
	//从第几条开始显示
	private int indexlastsum;

	public int getIndexlastsum() {
		return (pageindex-1)*pagesize;
	}

	private int pageindex=1; // 当前是第几页
	private  int pagesize = 5; // 每页显示多少条数据
	private long pagesum; // 共多少也
	private long pagetotal; // 共多少条数据
	private List pagelist; // 当前页的数据
	private StringBuffer first; // 首页
	private StringBuffer last; // 上一页
	private StringBuffer next; // 下一页
	private StringBuffer end; // 尾页
	private StringBuffer location; // 连接地址
	private Object obj;
	public Object getObj() {
		return obj;
	}

	public void setObj(Object obj) {
		this.obj = obj;
	}

	//排序的方式
	private String oneway;
	//排序的字段
	private String onetext;
	
	public int getPageindex() {
		
		return pageindex;
	}

	public void setPageindex(int pageindex) {
		this.pageindex = pageindex;
	}

	
	
	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}

	public long getPagesum() {
		if (pagetotal % pagesize == 0) {
			return pagetotal / pagesize;
		} else {
			return pagetotal / pagesize + 1;
		}
	}
	public void setPagesum(long pagesum) {
		this.pagesum = pagesum;
	}
	


	public long getPagetotal() {
		return pagetotal;
	}

	public void setPagetotal(long pagetotal) {
		this.pagetotal = pagetotal;
	}

	public List getPagelist() {
		return pagelist;
	}

	public void setPagelist(List pagelist) {
		this.pagelist = pagelist;
	}

	// 首页
	public StringBuffer getFirst() {

		StringBuffer buff = new StringBuffer();
		buff.append("<a href=" + getLocation() + "?queryUtils.pageindex=1>首页</a>");

		return buff;
	}
	public void setFirst(StringBuffer first) {
		this.first = first;
	}
	
	public StringBuffer getLast() {
		if (pageindex <= 0) {
			pageindex = 1;
		}
		StringBuffer buff = new StringBuffer();
		buff.append("<a href=" + getLocation() + "?queryUtils.pageindex="+(getPageindex()==1?1:getPageindex())+">上一页</a>");
		return buff;
	}
	public void setLast(StringBuffer last) {
		this.last = last;
	}
	
	public StringBuffer getNext() {
		if (pageindex >= getPagesum()) {
			pageindex = (int) getPagesum();
		}
		StringBuffer buff = new StringBuffer();
		buff.append("<a href=" + getLocation() + "?queryUtils.pageindex="
				+ (getPageindex()==getPagesum()?getPagesum():getPageindex()+1)+">下一页</a>");
		return buff;
	}
	public void setNext(StringBuffer next) {
		this.next = next;
	}
	
	public StringBuffer getEnd() {
		StringBuffer buff = new StringBuffer();
		buff.append("<a href=" + getLocation() + "?queryUtils.pageindex="
				+ getPagesum()+">尾页</a>");

		return buff;
	}
	public void setEnd(StringBuffer end) {
		this.end = end;
	}
	public StringBuffer getLocation() {
		return location;
	}
	public void setLocation(StringBuffer location) {
		this.location = location;
	}

	public String getOneway() {
		return oneway;
	}

	public void setOneway(String oneway) {
		this.oneway = oneway;
	}

	public String getOnetext() {
		return onetext;
	}

	public void setOnetext(String onetext) {
		this.onetext = onetext;
	}


	

}
